<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        table tr th,td{
            border: 1px solid black;
            text-align: center;
        }
        table{
            border: 1px;
            cell-padding:0;
            cell-spacing:0;
            width: 80%;
            margin-top: 20px;
        }
        table thead{
            background-color:#b3d7ff ;
        }
        a{
            cursor: pointer;
        }
        input{
             border-top: none;
             border-left: none;
             border-right: none;
             border-bottom: black solid 1px;
         }


    </style>
    <link rel="stylesheet" href="../css/pintuer.css">
    <link rel="stylesheet" href="../css/bootstrap.css">

    <script src="../js/jquery-3.4.1.min.js"></script>
    <script src="../js/popper.min.js"></script>
    <script src="../js/bootstrap-table1.15.3.js"></script>
    <script src="../js/bootstrap-table-zh-CN.min.js"></script>
    <script src="../js/bootstrap-min-4.3.1.js"></script>
    <script src="../js/pintuer.js"></script>
    <script src="../js/initMain.js"></script>
    <script type="text/javascript">
        function initTable(){
            $("#tableInfo").bootstrapTable({
                method:"post",
                contentType:"application/json",
                url:"/mManufacture/queryMManufactureCheckAndNoProcedure.action",
                //设置交替行样式
                striped:true,
                //初始显示页数
                pageNum:1,
                //是否显示分页
                pagination:true,
                //设置是服务端分页还是客户端分页
                sidePagination:"server",
                //页大小
                pageSize:3,
                //分页列表
                pageList: [3,5,6,10],
                //上传到服务器的参数
                queryParams:function (data) {
                    return{
                        //计算页号，当前号
                        pageNum:(data.offset/data.limit)+1,
                        //计算页大小
                        pageSize: data.limit,
                    }
                },
                columns:[

                    {title:"生产派工单编号",field:"manufactureId",align:"center"},
                    {title:"产品编号",field:"productId",align:"center"},
                    {title:"产品名称",field:"productName",align:"center"},
                    {title:"数量",field:"amount",align:"center"},
                    {title:"登记时间",field:"registerTime",align:"center"},
                    {title:"登记",field:"id",align:"center",formatter:function (value,row,index) {
                            return "<a href='#' onclick='addproceduring("+JSON.stringify(row)+")'  id='registerBtn"+row.id+"'>登记</a>"
                        }},
                ]

            })
        }
        var productId;
        $(function () {
            initTable();
            //工序登记确认提交
            $("#saveProceduring").click(function () {
                var b=true;
                var len=$("#MDesignModuleTable tbody tr").length;
                // alert(len);
                for(var i=0;i<len;i++){
                    // alert($(".renewAmount").eq(i).text());
                    // alert($(".userdAmount").eq(i).text());
                    // alert($(".amount").eq(i).val());
                    if($(".renewAmount").eq(i).text()-$(".userdAmount").eq(i).text()<$(".amount").eq(i).val()){
                        b=false;
                        alert("你输入的数量大于可用数量");
                    }
                }
                if(b==true||b=="true"){

                    var mProceduring=new Object();
                    mProceduring.parentId=mManufactureObj.id;
                    mProceduring.detailsNumber=mProcedureObj.detailsNumber;
                    mProceduring.procedureId=mProcedureObj.procedureId;
                    mProceduring.procedureName=mProcedureObj.procedureName;
                    mProceduring.labourHourAmount=$("#realLabourHourAmount").val();
                    mProceduring.costPrice=mProcedureObj.costPrice;
                    mProceduring.subtotal=mProceduring.labourHourAmount*mProceduring.costPrice;
                    mProceduring.procedureResponsiblePerson=$("#procedureResponsiblePerson").val();
                    mProceduring.register=$("#register1").text();
                    mProceduring.registerTime=$("#registerTime1").text();
                    //创建生产工序物料过程记录(M_PROCEDURE_MODULING)实体类数组
                    var MProcedureModulingArrs=[];
                    for(var i=0;i<$("#MDesignModuleTable tbody tr").length;i++){

                        var mProcedureModuling=new Object();
                        // alert(mProcedure.id);
                        //暂时将id设置为MDesignProcedureDetailsId
                        mProcedureModuling.id=$(".MDesignModuleId").eq(i).text();
                        mProcedureModuling.detailsNumber=i+1;
                        mProcedureModuling.productId=$(".productId").eq(i).text();
                        mProcedureModuling.productName=$(".productName").eq(i).text();
                        mProcedureModuling.costPrice=$(".costPrice").eq(i).text();
                        mProcedureModuling.amount=$(".amount").eq(i).val();
                        mProcedureModuling.subtotal=mProcedureModuling.costPrice*mProcedureModuling.amount;

                        MProcedureModulingArrs.push(mProcedureModuling);

                    }
                    $.ajax({
                        url:"/mProceduring/addMProceduring.action",
                        type: "post",
                        data:"mProceduringStr="+JSON.stringify(mProceduring)+"&MProcedureModulingArrsStr="+JSON.stringify(MProcedureModulingArrs)+"&mProcedureId="+mProcedureId,
                        success:function (data) {
                            $("#addDesignModel").modal("hide");
                            $("#MProcedureTable").bootstrapTable("refresh");
                            // alert(mProcedureId);
                        }
                    })
                }

            })
            $("#cancel").click(function () {
                $("#tableInfo").bootstrapTable("refresh");
            })
            $("#saveCheckTransferProceduring").click(function () {
                $.ajax({
                    data:"mProcedureId="+mProcedure2.id+"&realAmount="+$("#realAmount").val(),
                    type:"post",
                    url:"/mProcedure/transferProcedure.action",
                    success:function (data) {
                        // $("#MProcedureTable").bootstrapTable('destroy');
                        $("#MProcedureTable").bootstrapTable("refresh");
                        $("#transferProcedure").modal("hide");
                        //判断是否是最后一个交接登记复核
                        // alert(mProcedure.procedureName);
                        // alert($("#MProcedureTable tbody tr:last").children().eq(1).text());
                        if(mProcedure2.procedureName==$("#MProcedureTable tbody tr:last").children().eq(1).text()){
                            // alert(111);
                            $.ajax({
                                data:"mManufactureId="+mManufactureObj.id,
                                type:"post",
                                url:"/mManufacture/queryIfLastTransfer.action",
                                success:function (data) {
                                    $("#tableInfo").bootstrapTable("refresh");
                                }
                            })
                        }
                    }
                })

            })
        })
        var mManufactureObj;
        //点击登记时
        function addproceduring(mManufacture) {
            // alert(mManufacture.id);
            mManufactureObj=mManufacture;
            $("#MProcedureTable").bootstrapTable('destroy');
            $("#MProcedureTable").bootstrapTable({
                method:"post",
                contentType:"application/json",
                url:"/mProcedure/queryMProcedureByPId",
                //设置交替行样式
                striped:true,
                //初始显示页数
                pageNum:1,
                //是否显示分页
                pagination:true,
                //设置是服务端分页还是客户端分页
                sidePagination:"server",
                //页大小
                pageSize:3,
                //分页列表
                pageList: [3,5,6,10],
                //上传到服务器的参数
                queryParams:function (data) {
                    return{
                        //计算页号，当前号
                        pageNum:(data.offset/data.limit)+1,
                        //计算页大小
                        pageSize: data.limit,

                        mManufactureId:mManufactureObj.id
                    }
                },

                columns:[

                    {title:"序号",field:"detailsNumber",align:"center"},
                    {title:"工序名称",field:"procedureName",align:"center"},
                    {title:"实际工时数(小时)",field:"realLabourHourAmount",align:"center"},
                    {title:"设计工时数(小时)",field:"labourHourAmount",align:"center"},
                    {title:"设计工时成本(元)",field:"subtotal",align:"center"},
                    {title:"实际工时成本",field:"realSubtotal",align:"center"},
                    {title:"设计物料成本",field:"moduleSubtotal",align:"center"},
                    {title:"实际物料成本",field:"realModuleSubtotal",align:"center"},
                    {title:"工序登记",field:"procedureFinishTag",align:"center",formatter:function (value,row,index) {
                            if(value=='G004-0'){
                                return "<a href='#' onclick='designProceduring("+JSON.stringify(row)+")'  >登记</a>"
                            }else if(value=='G004-3'){
                                return "<span>已复核</span>";
                            }else{
                                return "<span>完成</span>"
                            }
                        }},
                    {title:"交接登记",field:"procedureTransferTag",align:"center",formatter:function (value,row,index) {
                            if(value=='G005-0'&&row.procedureFinishTag=='G004-3'){
                                return "<a  href='#' onclick='transferProcedure("+JSON.stringify(row)+")' >交接登记</a>"
                            }else if(value=='G005-2'){
                                return "<span>已复核</span>";
                            }else if(value=='G005-0'){
                                return "";
                            }else {
                                return "完成";
                            }
                        }}
                ],onLoadSuccess:function () {
                    $("#addModel").modal("show");
                    $("#manufactureId").text(mManufacture.manufactureId);
                    $("#amount").text(mManufacture.amount);
                    $("#productName").text(mManufacture.productName);
                    $("#productId").text(mManufacture.productId);
                    $("#moduleCostPriceSum").text(mManufacture.moduleCostPriceSum);
                    $("#realModuleCostPriceSum").text(mManufacture.realModuleCostPriceSum);
                    $("#realLabourCostPriceSum").text(mManufacture.realLabourCostPriceSum);
                    $("#labourCostPriceSum").text(mManufacture.labourCostPriceSum);
                    $("#register").text(mManufacture.register);
                    $("#registerTime").text(mManufacture.registerTime);
                    $("#remark").text(mManufacture.remark);
                }
            })


        }
        var mProcedure2;
        //点击交接登记：前提 工序登记后确认“完成”并已做生产登记复核
        function transferProcedure(mProcedure) {
            // alert($("#MProcedureTable tbody tr:last").children().eq(0).text());
            mProcedure2=mProcedure;
            $("#transferProcedure").modal("show");
            $("#demandAmount").text(mProcedure.demandAmount);
            $("#procedureId1").text(mProcedure.procedureId);
            $("#procedureName1").text(mProcedure.procedureName);

            // var realAmount = prompt("本工序投产数量:"+mProcedure.demandAmount+"\n请输入合格品数量");
            // alert(mProcedure.id);
        }


        function initMDesignModule() {
            $("#MDesignModuleTable").bootstrapTable({
                method:"post",
                contentType:"application/json",
                url:"/mProcedureModule/queryMProcedureModuleByPId.action",
                //设置交替行样式
                striped:true,
                //初始显示页数
                pageNum:1,
                //是否显示分页
                pagination:true,
                //设置是服务端分页还是客户端分页
                sidePagination:"server",
                //页大小
                pageSize:3,
                //分页列表
                pageList: [3,5,6,10],
                //上传到服务器的参数
                queryParams:function (data) {
                    return{
                        //计算页号，当前号
                        pageNum:(data.offset/data.limit)+1,
                        //计算页大小
                        pageSize: data.limit,

                        pId:mProcedureId
                    }
                },

                columns:[

                    {title:"ID",field:"id",hidden:true,align:"center",formatter:function (value,row,index) {
                            return "<span class='MDesignModuleId'>"+value+"</span>"
                        }},
                    {title:"序号",field:"detailsNumber",align:"center"},
                    {title:"物料名称",field:"productName",align:"center",formatter:function (value,row,index) {
                            return "<span class='productName'>"+value+"</span>"
                        }},
                    {title:"物料编号",field:"productId",align:"center",formatter:function (value,row,index) {
                            return "<span class='productId'>"+value+"</span>"
                        }},
                    {title:"单位物料成本",field:"costPrice",align:"center",formatter:function (value,row,index) {
                            return "<span class='costPrice'>"+value+"</span>"
                        }},
                    {title:"设计数量",field:"amount",align:"center"},
                    {title:"调度出库数量",field:"renewAmount",align:"center",formatter:function (value,row,index) {
                            return "<span class='renewAmount'>"+value+"</span>"
                        }},
                    {title:"已使用数量",field:"realAmount",align:"center",formatter:function (value,row,index) {
                            return "<span class='userdAmount'>"+value+"</span>"
                        }},
                    {title:"本次数量",field:"id",align:"center",formatter:function (value,row,index) {
                            return "<input type=\"text\" class='amount' onkeyup=\"this.value=this.value.replace(/\\D/g,'')\" size='3px'>";
                    }}
                ]
            })
        }
        function init() {

        }
        var mProcedureId;
        var mProcedureObj;
        //点击登记显示生产登记单
        function designProceduring(mProcedure) {
            mProcedureObj=mProcedure;
            mProcedureId=mProcedure.id;
            // alert(mManufactureObj.manufactureId);
            // 严格要求本工序对应的所有物料已调度出库，才能进行工序登记
            // 严格要求按顺序进行工序登记，上一个工序未完成时不能对下一个工序进行登记
            $.ajax({
                url:"/sPay/queryModuleIfStore.action",
                type:"post",
                data:"manufactureId="+mManufactureObj.manufactureId+"&id="+mManufactureObj.id+"&mProcedureDetailsNumber="+mProcedure.detailsNumber,
                success:function (data) {
                    if(data=="-1"||data==-1){
                        alert("本工序对应的所有物料已调度出库，才能进行工序登记！");
                    }else if(data=="-2"||data==-2){
                        alert("请先完成之前的工序登记！")
                    }else{
                        // alert(mProcedure.id);
                        $("#addDesignModel").modal("show");
                        $("#MDesignModuleTable").bootstrapTable('destroy');
                        initMDesignModule();
                        $("#manufactureId1").text(mManufactureObj.manufactureId);
                        $("#procedureName").text(mProcedure.procedureName);
                        $("#labourHourAmount").text(mProcedure.labourHourAmount);
                        $("#userdLabourHourAmount").text(mProcedure.realLabourHourAmount);
                        $("#register1").text(localStorage.getItem("userName"));
                        var date=new Date();
                        $("#registerTime1").text(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+"  "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());
                        $("#MProcedureTable").bootstrapTable("refresh");
                    }
                }
            })

        }
    </script>
</head>
<body>
    <div>

        <table id="tableInfo">

        </table>
    </div>
    <div class="modal  fade" id="addModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 90%">
            <div class="modal-content" style="border: 1px solid black;">
                <div class="modal-header">
                    <div class="container">
                        <div class="row">
                            <div class="col-7" style="text-align: right">
                                <h5 class="modal-title" id="info" >
                                    生产派工单
                                </h5>
                            </div>
                            <div class="col-3"></div>
                            <div class="col-2" style="position: absolute;right: 30px"></div>
                        </div>
                    </div>
                    <button id="cancel" type="button" class="close" data-dismiss="modal" aria-hidden="true" style="margin-right: 0px">

                    </button>
                </div>
                <div class="modal-body">
                    <form id="addProcedureForm">
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-2" style="text-align: right">
                                    <span>派工单编号：</span>
                                </div>
                                <div class="col-4">
                                    <span id="manufactureId"></span><br>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    数量：
                                </div>
                                <div class="col-4">
                                    <span id="amount"></span>
                                </div>

                            </div>
                        </div><br>

                        <div class="container">
                            <div class="row">
                                <div class="col-2" style="text-align:right">
                                    产品名称：
                                </div>
                                <div class="col-4">
                                    <span id="productName">笔记本</span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    产品编号：
                                </div>
                                <div class="col-4">
                                    <span id="productId" >20001002192001</span>
                                </div>
                            </div>
                        </div><br>
                        <div class="container">
                            <div class="row">
                                <div class="col-2" style="text-align:right">
                                    设计物料总成本：
                                </div>
                                <div class="col-4">
                                    <span id="moduleCostPriceSum"></span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    实际物料总成本：
                                </div>
                                <div class="col-4">
                                    <span id="realModuleCostPriceSum"></span>
                                </div>
                            </div>
                        </div><br>
                        <div class="container">
                            <div class="row">
                                <div class="col-2" style="text-align:right">
                                    设计工时总成本：
                                </div>
                                <div class="col-4">
                                    <span id="labourCostPriceSum"></span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    实际工时总成本：
                                </div>
                                <div class="col-4">
                                    <span id="realLabourCostPriceSum"></span>
                                </div>
                            </div>
                        </div><br>


                        <table id="MProcedureTable"  style="margin-left: 20px">

                        </table><br>

                        <div class="container">
                            <div class="row">
                                <div class="col-2" style="text-align:right">
                                    登记人：
                                </div>
                                <div class="col-4">
                                    <span name="register" id="register"></span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    登记时间：
                                </div>
                                <div class="col-4">
                                    <span  name="registerTime" id="registerTime"></span>
                                </div>
                            </div>
                        </div><br>
                        <div class="container">
                            <div class="row">
                                <div class="col-2" style="text-align:right">
                                    复核人：
                                </div>
                                <div class="col-4">
                                    <span name="register" id="checker"></span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    复核时间：
                                </div>
                                <div class="col-4">
                                    <span  name="registerTime" id="checkTime"></span>
                                </div>
                            </div>
                        </div><br>
                        <span style="margin-left: 55px">备注：</span>
                        <span style="width: 550px;margin-left: 150px"  id="remark">

                        </span>

                    </form>
                </div>

            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>


<!--    设计工序物料-->
    <div class="modal  fade" id="addDesignModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 90%;">
            <div class="modal-content" style="border: 1px solid black;">
                <div class="modal-header">
                    <div class="container">
                        <div class="row">
                            <div class="col-7" style="text-align: right"></div>
                            <div class="col-3"></div>
                            <div class="col-2" style="position: absolute;right: 30px">
                                <button class="btn btn-primary"  id="saveProceduring" >提交</button>
                            </div>
                        </div>
                    </div>
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="margin-right: 0px"></button>
                </div>
                <div style="width: 80%;height: 550px;border: 2px solid gray;margin: 0 auto;margin-top: 10px">
                    <h3 align="center" style="margin-top: 30px">生产登记单</h3>
                    <div class="container-fluid">
                        <form id="putRegister">
                            <div class="row" style="margin-top: 30px;">
                                <div class="col-2" style="text-align:right">
                                    派工单编号：
                                </div>
                                <div class="col-4">
                                    <span id="manufactureId1"></span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    工序名称：
                                </div>
                                <div class="col-4">
                                    <span id="procedureName"></span>
                                </div>

                            </div>
                            <div class="row" style="margin-top: 30px;">
                                <div class="col-2" style="text-align:right">
                                    负责人：
                                </div>
                                <div class="col-4">
                                    <input id="procedureResponsiblePerson"/>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    设计工时数：
                                </div>
                                <div class="col-4">
                                    <span id="labourHourAmount"></span>
                                </div>

                            </div>
                            <div class="row" style="margin-top: 30px;">
                                <div class="col-2" style="text-align:right">
                                    已用工时数：
                                </div>
                                <div class="col-4">
                                    <span id="userdLabourHourAmount"></span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    本次工时数：
                                </div>
                                <div class="col-4">
                                    <input id="realLabourHourAmount" type="text" onkeyup="this.value=this.value.replace(/\D/g,'')">
                                </div>

                            </div><br/>

                            <div>
                                <table id="MDesignModuleTable" width="80%" style="margin-top: 20px;" class="table table-sm">

                                </table>
                            </div>
                            <div class="row" style="margin-top: 30px;">
                                <div class="col-2" style="text-align:right">
                                    登记人：
                                </div>
                                <div class="col-4">
                                    <span id="register1"></span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    登记时间：
                                </div>
                                <div class="col-4">
                                    <span id="registerTime1"></span>
                                </div>

                            </div>


                        </form>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="modal  fade" id="transferProcedure" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 90%;">
            <div class="modal-content" style="border: 1px solid black;">
                <div class="modal-header">
                    <div class="container">
                        <div class="row">
                            <div class="col-7" style="text-align: right"></div>
                            <div class="col-3"></div>
                            <div class="col-2" style="position: absolute;right: 30px">
                                <button class="btn btn-primary"  id="saveCheckTransferProceduring" >通过</button>
                            </div>
                        </div>
                    </div>
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="margin-right: 0px"></button>
                </div>
                <div style="width: 70%;height: 350px;border: 2px solid gray;margin: 0 auto;margin-top: 10px">
                    <h3 align="center" style="margin-top: 30px">交接登记复核</h3><hr>
                    <div class="container-fluid">
                        <div class="row" style="margin-top: 30px;">
                            <div class="col-2" style="text-align:right">
                                工序编号：
                            </div>
                            <div class="col-4">
                                <span id="procedureId1"></span>
                            </div>
                            <div class="col-2" style="text-align:right">
                                工序名称：
                            </div>
                            <div class="col-4">
                                <span id="procedureName1"></span>
                            </div>

                        </div>
                        <div class="row" style="margin-top: 30px;">
                            <div class="col-2" style="text-align:right">
                                本工序投产数量：
                            </div>
                            <div class="col-4">
                                <span id="demandAmount"></span>
                            </div>
                            <div class="col-2" style="text-align:right">
                                本工序合格数量：
                            </div>
                            <div class="col-4">
                                <input id="realAmount"/>
                            </div>

                        </div>

                    </div>
                </div>
                <div style="height: 300px">

                </div>

            </div>
        </div>
    </div>
</body>

</html>